import java.util.Set;

public class Leetcode2299 {
    public static void main(String[] args) {
        System.out.println(strongPasswordCheckerII("IloveLe3tcode!"));
        System.out.println(strongPasswordCheckerII("Me+You--IsMyDream"));
        System.out.println(strongPasswordCheckerII("1aB!"));

    }

    private static final Set<Character> SPECIAL_CHARACTERS = Set.of('!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+');

    public static boolean strongPasswordCheckerII(String password) {
        if (password == null || password.length() < 8) {
            return false;
        }

        boolean lowercaseFlag = false;
        boolean capitalFlag = false;
        boolean numberFlag = false;
        boolean specialCharacterFlag = false;

        char[] passwordChars = password.toCharArray();
        char parent = ' ';
        for (char c : passwordChars) {
            if (c <= 'z' && c >= 'a') {
                lowercaseFlag = true;
            }

            if (c <= 'Z' && c >= 'A') {
                capitalFlag = true;
            }

            if (c >= '0' && c <= '9') {
                numberFlag = true;
            }

            if (SPECIAL_CHARACTERS.contains(c)) {
                specialCharacterFlag = true;
            }

            if (parent == c) {
                return false;
            }

            parent = c;
        }

        return lowercaseFlag && capitalFlag && numberFlag && specialCharacterFlag;
    }
}
